if (typeof(console) == 'undefined') {
	console = {log: function(m){alert(m);}};
}
var Debug = $.inherit({}, {
	dump: function(obj, options){
		options = $.extend({name: ($.isArray(obj)? 'Array': 'Object'), full: false, indent: '', depth: 1, depthMax: 3, maxLength: 100, newLine: '\n', indentSymb: '⋅   ', showType: false}, options);
		var depth = options.depth, indent = options.indent;
		if (depth > options.depthMax) {
			return indent + (options.showType? '{' + typeof(obj) + '} ': '') + options.name + ": [Maximum Depth Reached]" + options.newLine;
		}

		if (typeof obj == "object") {
			var child = null;
			var output = indent + options.name + ":" + options.newLine;
			indent += options.indentSymb;
			try {
				for (var item in obj) {
					try {
						child = obj[item];
					} catch (e) {
						return indent + (options.showType? '{' + typeof(child) + '} ': '') + options.name + "[Unable to Evaluate]" + options.newLine;
					}
					if (typeof(child) == 'function' && !options.full) {
						 child = '[function]';
					} else if (typeof(child) == 'string' && child.length > options.maxLength && !options.full) {
						 child = '[long string]';
					} else if (typeof(child) == 'string') {
						child = '"' + child + '"';
					} else if (child === null) {
						child = 'null';
					}
					if (typeof child == "object") {
						output += this.dump(child, $.extend(options, {name: item, depth: depth + 1, indent: indent}));// + options.newLine;
					} else {
						output += '' + indent + (options.showType? '{' + typeof(child) + '} ': '') + item + ": " + child + options.newLine;
					}
				}
			} catch (e) {}
			return output;
		} else {
			return obj;
		}
	},
	dumpAlert: function(obj, options) {
		alert(this.dump(obj, options));
	},
	dumpLog: function(obj, options) {
		console.log(this.dump(obj, options));
	},
	dumpTo: function(obj, options, to) {
		to = to || 'debug';
		var jTo = $('#' + to + ':first');
		if (jTo.size() != 1) {
			$('body:first').append(jTo = $('<pre id="' + to + '"></pre>'));
		}
		jTo.text(this.dump(obj, options));
	}
});
